# TODO: 读取训练结果直接识别
# DATE: 2022/3/24
# AUTHOR: Cheng Ze WUST

import numpy as np
import tensorflow as tf
import os
from PIL import Image
os.environ['(TF_CPP_MIN)LOG_LEVEL']='2'

new_model=tf.keras.models.load_model('mnist.model')
print(new_model.summary())

#region 精确度
minist=tf.keras.datasets.mnist
(train_img,train_lables),(test_img,test_lables)=tf.keras.datasets.mnist.load_data()
train_lables=train_lables[:10000]   #训练数据取前10000条
test_lables=test_lables[:10000]
train_img=train_img[:10000].reshape(-1,28*28)/255.0
test_img=test_img[:10000].reshape(-1,28*28)/255.0

loss,acc=new_model.evaluate(test_img,test_lables)
print("精度：{:5.2f}%".format(100*acc))
#endregion

print(np.argmax(new_model.predict(test_img[1480:1481])))
print(test_lables[1480:1481])

def img_show(img):
    pil_img=Image.fromarray(np.uint8(img))
    pil_img.show()
img_show((255*test_img[1480:1481]).reshape(28,28))

